package start.rabbitmq;

import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.domain.Range;
import org.springframework.data.redis.connection.stream.*;
import org.springframework.data.redis.core.StreamOperations;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.scheduling.annotation.Scheduled;

import javax.annotation.PostConstruct;
import java.time.Duration;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

@Configuration      //1.主要用于标记配置类，兼备Component的效果。
@Slf4j
public class RabbitProducer {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    public void deadRecordListen() {
        log.info("开始发送消息");
        String messageData = "[%s]test message, hello!";
        for (int i=0; i< 100; i++) {
            String messageId = String.valueOf(UUID.randomUUID());
            Map<String,Object> map=new HashMap<>();
            map.put("index", (i+1));
            map.put("messageId",messageId);
            map.put("messageData",String.format(messageData, (i+1)));
            //将消息携带绑定键值：TestDirectRouting 发送到交换机TestDirectExchange
            rabbitTemplate.convertAndSend("TestDirectExchange", "TestDirectRouting", JSON.toJSONString(map));
            //将消息携带绑定键值：dddTopic.t1 发送到交换机TestTopicExchange
            rabbitTemplate.convertAndSend("TestTopicExchange", "dddTopic.t1", map);

            MessageModel<Map> messageModel = new MessageModel<>();
            messageModel.setData(map);
            rabbitTemplate.convertAndSend("exchange.fmc.biz", "key.queue.callback.FSSC-demo", JSON.toJSONString(messageModel));

            //rabbitTemplate.convertAndSend("TestTopicQueue", "dddTopic-t1", JSON.toJSONString(map));

        }
        log.info("1000条记录发送完毕");



    }
}

